<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>提现管理</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link href="{__STATIC__}/layuiAdmin/layui/css/layui.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/adminui/dist/css/admin.css" rel="stylesheet">
	<link href="{__STATIC__}/layuiAdmin/style/style.css" rel="stylesheet">
</head>
<body>
	<div class="layui-fluid">
		<div class="layui-card">
			<div class="layui-card-body">
				<div style="padding-bottom: 10px;">
					<div class="layui-table-title">提现管理</div>
					<div class="layui-form search_ctr">
						<div class="layui-form-item">
							<div class="layui-input-inline w160">
								<input type="text" name="k3" id="k3" class="layui-input" placeholder="开始时间" autocomplete="off" value="">
							</div>
							<div class="layui-form-mid layui-word-aux">-</div>
							<div class="layui-input-inline w160">
								<input type="text" name="k4" id="k4" class="layui-input" placeholder="结束时间" autocomplete="off" value="">
							</div>
							<div class="layui-input-inline">
								<input type="text" name="keys" placeholder="输入用户名/手机/昵称查询" class="layui-input">
							</div>
							<div class="layui-input-inline w120">
								<select name="k2">
									<option value="">提现状态</option>
									<option value="0">待审</option>
									<option value="1">通过</option>
									<option value="-1">拒绝</option>
								</select>
							</div>
							<button class="layui-btn layui-btn-normal" lay-submit lay-filter="LAY-search">查询</button>
						</div>
					</div>
				</div>

				<table id="LAY-table" lay-filter="LAY-table"></table>
				<script type="text/html" id="name">
					{{d.type}}
					{{#  if(d.type == '银行卡'){ }}
					    ({{d.cash_bank}},{{d.cash_name}},{{d.bank_account}})
					{{#  } }}
					{{#  if(d.type == '微信'){ }}
					    ({{d.cash_name}},{{d.bank_account}})
					{{#  } }}
					{{#  if(d.type == '支付宝'){ }}
					    ({{d.cash_name}},{{d.bank_account}})
					{{#  } }}
				</script>
				<script type="text/html" id="state">
					{{#  if(d.cash_state == 0){ }}
					<span class="layui-badge-dot layui-bg-blue"></span>待审
					{{#  } }}
					{{#  if(d.cash_state == 1){ }}
					<span class="layui-badge-dot layui-bg-green"></span>通过
					{{#  } }}
					{{#  if(d.cash_state == -1){ }}
					<span class="layui-badge-dot layui-bg-gray"></span>拒绝
					{{#  } }}
				</script>
				<script type="text/html" id="tableBar">
					{{#  if(d.cash_state == 0){ }}
					<a class="link-text" lay-event="opt">操作</a>
					{{#  } else { }}
					<a class="no-link-text">操作</a>
					{{#  } }}
				</script>
			</div>
		</div>
	</div>
</body>
</html>
<script src="{__STATIC__}/layuiAdmin/layui/layui.js"></script>
<script>
	layui.config({
		base: '{__STATIC__}/layuiAdmin/' // 静态资源所在路径
	}).use(['index', 'layer', 'table', 'form', 'laydate', 'dropdown'], function(){
		let $ = layui.$;
		let layer = layui.layer;
		let table = layui.table;
		let form = layui.form;
		let laydate = layui.laydate;
		let dropdown = layui.dropdown;

		//搜索日期
		laydate.render({
			elem: '#k3'
			,type: 'datetime'
			,trigger: 'click'
		});

		laydate.render({
			elem: '#k4'
			,type: 'datetime'
			,trigger: 'click'
		});

		//初始化列表
		table.render({
			elem: '#LAY-table'
			,url: "{:url('getList')}"
			,cols: [[
				{field: 'id', width: 80, title: 'ID', sort: true}
				,{field: 'user_id', width:150, title: '会员[编号]'}
				,{field: 'fee', width: 120, title: '提现金额'}
				,{field: 'service_fee', width: 120, title: '服务费'}
				,{field: 'cash_name', width: 280, title: '收款账号', templet: '#name'}
				,{field: 'info', minWidth: 200, title: '备注'}
				,{field: 'cash_state', width: 100, title: '状态', templet: '#state'}
				,{field: 'add_date', width: 180, title: '时间'}
				,{title: '操作', width: 52, align:'center', fixed: 'right', toolbar: '#tableBar'}
			]]
			,page: true
			,limit: 20
			,height: 'full-100'
			,text: {none: '暂无相关数据'}
		});

		//监听搜索
		form.on('submit(LAY-search)', function(data){
			let field = data.field;
			//执行重载
			table.reload('LAY-table', {
				url: "{:url('getList')}"
				,where: field
				,page: {
					curr: 1 //重新从第 1 页开始
				}
			});
		});

		//表格内操作按钮
		table.on('tool(LAY-table)', function(obj){
			let tableData = obj.data;
			if(obj.event === 'opt'){
				// 更多下拉菜单
				let data = [];
				if(tableData.cash_state == 0) {
					//待付款
					data = [
						{
							title: '通过',
							id: 'agree'
						},
						{
							title: '拒绝',
							id: 'refuse'
						}
					];
				}
				dropdown.render({
					elem: this,
					show: true, // 外部事件触发即显示
					data: data,
					click: function(data){
						//根据 id 做出不同操作
						if(data.id === 'agree'){
							layer.confirm('确定付款到账了吗？', function(){
								$.ajax({
									type:"post",
									url:"{:url('agree')}",
									data: {
										m_id:tableData.id
									},
									dataType:"json",
									beforeSend: function () {
										layer.load(1);
									},
									success:function(res){
										layer.closeAll();
										if(res.code == 0){
											if(res.msg == 'success') {
												layer.msg('操作成功', {
													time: 1500
												}, function(){
													table.reloadData('LAY-table',{},true); //数据刷新
												});
											} else {
												layer.msg(res.msg);
											}
										} else {
											layer.msg(res.msg);
										}
									}
								});
							});
						}
						if(data.id === 'refuse'){
							layer.open({
								type: 2
								,title: '提现失败'
								,content: "{:url('editCash')}?id=" + tableData.id
								,maxmin: false
								,area: ['500px', '280px']
								,btn: ['确定', '取消']
								,yes: function(index, layero){
									let iframeWindow = window['layui-layer-iframe'+ index];
									let submitID = 'LAY-submit';
									let submit = layero.find('iframe').contents().find('#'+ submitID);

									//监听提交
									iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
										let field = data.field; //获取提交的字段
										$.ajax({
											type:"post",
											url:"{:url('saveCash')}",
											data: {
												m_info:field.m_info,
												m_id:field.m_id
											},
											dataType:"json",
											beforeSend: function () {
												layer.load(1);
											},
											success:function(res){
												layer.closeAll();
												if(res.code == 0){
													table.reloadData('LAY-table',{},true); //数据刷新
												}
												else {
													layer.msg(res.msg);
												}
											}
										});
									});
									submit.trigger('click');
								}
							});
						}
					},
					align: 'right', // 右对齐弹出
					style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);', //设置额外样式
					className: 'order_dropdown'
				})
			}
		});

	});
</script>